# selenium: 自动化检测工具
# 可以打开浏览器，像人一样操作浏览器
# 程序员可以从selenium中提取网页上的各种信息
# 搭建环境
from selenium.webdriver import Edge
from selenium.webdriver.common import by
from selenium.webdriver.common import keys
import time
"""

# 创建浏览器对象
web = Edge()
# 打开一个网址
web.get('http://www.baidu.com')
print(web.title)

"""
web = Edge()
web.get('http://lagou.com')
# 找到一个元素，click点击事件
web.find_element(by.By.XPATH,'/html/body/div[10]/div[1]/div[2]/div[2]/div[1]/div/p[1]/a').click()
time.sleep(1)   # 让浏览器等一会,网站刷新都要等一下
# 找到输入框，输入内容
# 可以 @ 输入回车 @ 直接点击搜素
# web.find_element(by.By.XPATH,'/html/body/div[7]/div[1]/div[1]/div[1]/form/input[1]').send_keys('python')
# web.find_element(by.By.XPATH,'/html/body/div[7]/div[1]/div[1]/div[1]/form/input[5]').click()
web.find_element(by.By.XPATH,'/html/body/div[7]/div[1]/div[1]/div[1]/form/input[1]').send_keys('python',keys.Keys.ENTER)
time.sleep(1)
# 找所要爬取的数据
div_list = web.find_elements(by.By.XPATH,'/html/body/div/div[1]/div/div[2]/div[3]/div/div[1]/div')

for i in div_list:
    job_name = i.find_element(by.By.XPATH,'./div[1]/div[1]/div[1]/a').text
    job_salary = i.find_element(by.By.XPATH,'./div[1]/div[1]/div[2]/span').text
    print(job_name,job_salary)

